/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
package openbackup.system.base.sdk.job.model;

import lombok.Getter;

/**
 * 任务类型优先级
 *
 */
public enum JobTypePriorityEnum {
    // 恢复、即时恢复------------3000
    RESTORE("RESTORE", 3000),
    INSTANT_RESTORE("INSTANT_RESTORE", 3000),
    // 即时挂载------------2500
    LIVE_MOUNT("live_mount", 2500),
    // Agent推送安装、更新等------------2400
    HOST_REGISTER("host_register", 2400),
    PROTECT_AGENT_UPDATE("protect_agent_update", 2400),
    PROTECT_AGENT_UPDATE_PLUGIN_TYPE("protect_agent_update_plugin_type", 2400),
    // 备份、归档、复制
    BACKUP("BACKUP", 2000),
    ARCHIVE("archive", 2000),
    COPY_REPLICATION("copy_replication", 2000),
    // 解除即时挂载、迁移、防勒索
    UNMOUNT("unmount", 1000),
    MIGRATE("migrate", 1000),
    ANTI_RANSOMWARE("anti_ransomware", 1000),
    // 副本删除
    COPY_DELETE("COPY_DELETE", 0);

    private final String type;

    @Getter
    private final Integer value;

    JobTypePriorityEnum(String type, Integer value) {
        this.type = type;
        this.value = value;
    }

    /**
     * 根据任务类型获取优先级
     *
     * @param jobType 任务类型
     * @return 任务优先级
     */
    public static Integer getValueByType(String jobType) {
        for (JobTypePriorityEnum typeEnum : JobTypePriorityEnum.values()) {
            if (typeEnum.type.equals(jobType)) {
                return typeEnum.value;
            }
        }
        return 0;
    }
}